package javaBase.javaString;

/**
 * http://blog.sina.com.cn/s/blog_6b04c8eb0100tj1i.html
 * Created by Administrator on 2017/4/11 0011.
 */
public class StringManage {
    public static void testSubstring() {
        String a = "qwerasdf1234";
        System.out.println("substring1==" + a.substring(8, 12));
        System.out.println("substring2==" + a.substring(4));
    }

    public static void testConcat() {
        String a = "qwer";
        String b = "1234";
        System.out.println("concat==" + a.concat(b));
    }

    public static void testReplace() {
        String a = "Hello1234/deces\\cf";
        System.out.println("replace==" + a.replace("d", "w"));
        System.out.println("replace==" + a.replaceFirst("l", "W"));
        System.out.println("replace==" + a.replaceAll("\\d", "w"));
        System.out.println("replace==" + a.replace("ll", "ww"));
        System.out.println("replace==" + a.replaceAll("\\\\", "\\\\\\\\"));

    }

    public static void testValueOf() {
        String a = "124";
        boolean b = false;
        char[] c = new char[]{'a', 'b', 'c'};
        System.out.println(String.valueOf(a));
        System.out.println(String.valueOf(b));
        System.out.println(String.valueOf(c));
    }

    public static void testCharAt() {
        String a = "testCharAt";
        System.out.println(a.charAt(3));
    }

    public static void testGetChars() {
        String a = "testGetChars";
        char[] c = new char[20];
        a.getChars(2, 6, c, 4);
        for (char h : c
                ) {
            System.out.println(h);
        }
    }

    public static void testToCharArray() {
        String a = "test123你好";
        char[] c = a.toCharArray();
        for (char h : c
                ) {
            System.out.println(h);
        }
    }

    public static void testRegionMatches() {
        String a = "regionmatches";
        String b = "testRegionMatches";
        System.out.println("testRegionMatches ==" + a.regionMatches(true,0, b, 4, 13));
    }

    public static void testStartEndWith(){
        String a = "testStartEndWith";
        System.out.println("StartWith="+a.startsWith("test"));
        System.out.println("EndWith="+a.endsWith("EndWith"));
    }

    public static void testIndexOf(){
        String a = "testindextest";
        System.out.println(a.indexOf("t"));
        System.out.println(a.lastIndexOf("t"));
    }

    public static void main(String[] args) {
        //testSubstring();
        //testReplace();
        //testValueOf();
        //testCharAt();
        //testGetChars();
        //testToCharArray();
        //testRegionMatches();
        //testStartEndWith();
        testIndexOf();
    }
}
